package com.ruoyi.web.rabbitmq;

import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.rabbitmq.client.Channel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.common.config.PortalConfig;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 监听用户变更消息
 *
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class UserChangedReceiver {

    @Autowired
    private UserChangedService userChangedService;

    @Autowired
    private PortalConfig portalConfig;

    @RabbitHandler
//    @RabbitListener(queues = "user_1767368915755896832")
    public void handleUserChange(Message message, Channel channel) {
        try {
            userChangedService
                    .processUserChange("user_1767368915755896832", message, channel, portalConfig.getAppId());
        } catch (Exception e) {
            log.error("handleUserChange error", e);
        }
    }
}
